<template>
  <div class="orderedit" :style="{width:'600px', padding:'20px',paddingTop:'25px'}">
    <Form :model="formItem" :label-width="80">
      <FormItem label="订单id">{{formItem.id}}</FormItem>
      <FormItem label="快递单号">
        <Input v-model="formItem.order_no"/>
      </FormItem>
      <FormItem label="快递费用">
        <Input v-model="formItem.express_fee"/>
      </FormItem>
      <FormItem label="收件人">
        <Input v-model="formItem.accept_name"/>
      </FormItem>
      <FormItem label="收货电话">
        <Input v-model="formItem.telphone"/>
      </FormItem>
      <FormItem label="收货手机">
        <Input v-model="formItem.mobile"/>
      </FormItem>
      <FormItem label="收货邮箱">
        <Input v-model="formItem.email"/>
      </FormItem>
      <FormItem label="收获地区">
        <Input v-model="formItem.area"/>
      </FormItem>
      <FormItem label="收货地址">
        <Input v-model="formItem.address" type="textarea" :autosize="{minRows: 2,maxRows: 5}"/>
      </FormItem>
      <FormItem label="收获备注">
        <Input v-model="formItem.message" type="textarea" :autosize="{minRows: 2,maxRows: 5}"/>
      </FormItem>
      <FormItem label="总金额">
        <Input v-model="formItem.order_amount"/>
      </FormItem>
      <FormItem style="width:300px">
        <Select v-model="formItem.status">
          <Option
            :value="item.statusId"
            v-for="(item,index) 
                in statusNames"
            :key="index"
          >{{item.statusNew}}</Option>
        </Select>
      </FormItem>
      <FormItem>
        <Button type="primary" @click="setOrderData">保存</Button>
        <Button style="margin-left: 8px" @click="getOrderMessage">重置</Button>
      </FormItem>
    </Form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formItem: {},
      statusNames: [
        { statusId: 0, statusNew: "全部" },
        { statusId: 1, statusNew: "待付款" },
        { statusId: 2, statusNew: "已付款" },
        { statusId: 3, statusNew: "已发货" },
        { statusId: 4, statusNew: "已签收" },
        { statusId: 5, statusNew: "已取消" }
      ],
      postOrderData: {
        orderinfo: {
          id: 3,
          express_no: "",
          express_fee: 8,
          accept_name: "ivanyb",
          telphone: "",
          mobile: "186234234234",
          email: "",
          area: "江苏省,无锡市,惠山区",
          address: "城区",
          message: "",
          order_amount: 3307,
          orderstatus: "2"
        }
      }
    };
  },
  mounted() {
    this.getOrderMessage()
  },
  methods: {
    setOrderData() {
      let obj = this.postOrderData.orderinfo;
      obj.express_no = this.formItem.express_no;
      obj.express_fee = this.formItem.express_fee;
      obj.accept_name = this.formItem.accept_name;
      obj.telphone = this.formItem.telphone;
      obj.mobile = this.formItem.mobile;
      obj.email = this.formItem.email;
      obj.area = this.formItem.area;
      obj.message = this.formItem.message;
      obj.order_amount = this.formItem.order_amount;
      obj.orderstatus = this.formItem.orderstatus;
      this.$axios({
        url: "/admin/order/updateorder",
        method: "POST",
        data: this.postOrderData,
        withCredentials: true
      }).then(res => {
        if (res.data.status == 0) {
          this.$Message.success("数据修改完成");
          this.$router.back();
        }
      });
    },
    getOrderMessage() {
      this.$axios({
        url: `/admin/order/getorderdetial/${this.$route.params.ids}`
      }).then(res => {
        this.formItem = res.data.message.orderinfo;
      });
    }
  }
};
</script>
<style>
.ivu-form .ivu-form-item-label {
  font-size: 14px !important;
}
.ivu-form-item-content {
  font-size: 16px !important;
}
</style>
